import router from './router'
import store from './store'

const whiteList = ['/login', '/login/index', '/login/phone', '/login/account', '/login/bind', '/register'];

router.beforeEach((to, from, next) => {
  let token =  localStorage.getItem('access_token');
  // let token = 'xxxx';
  if (token) {
    /* has token*/
    if (to.path.indexOf('/login') != -1 && whiteList.indexOf(to.path) == -1) {
      next({ path: '/' })
    } else {
        const title = to.meta && to.meta.title;
        if (title) {
            document.title = title;
        }
        next();
    }
  } else {
    // 没有token
    if (whiteList.indexOf(to.path) !== -1) {
      // 在免登录白名单，直接进入
      next()
    } else {
      // next(`/login/index?redirect=${to.fullPath}`) // 否则全部重定向到登录页
      next()
    }
  }
})

router.afterEach(() => {
  
})
